/*
 * DbmsClientView.java
 */

package dbmsclient;

import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import java.net.*;

import application.Action;
import application.ResourceMap;
import application.SingleFrameApplication;
import application.FrameView;
import application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;



/**
 * The application's main frame.
 */
public class DbmsClientView extends FrameView {

	private DbmsClientLanguage language = new DbmsClientLanguage();
	
    public DbmsClientView(SingleFrameApplication app) {
        super(app);
		
		language.setEnglish(false);
		
        initComponents();
     
        bundle = java.util.ResourceBundle.getBundle("dbmsclient/Russian"); 
        jRadioButtonMenuItem2.setSelected(true);
        jRadioButtonMenuItem1.setSelected(false);
        reloadComponents();
        
        queryInputTextArea.addCaretListener(new CaretListener(){

            public void caretUpdate(CaretEvent e) {
                positionLabel.setText(String.valueOf(e.getDot()));
            }
        });
        statusMessageLabel.setText(java.util.ResourceBundle.getBundle("dbmsclient/Russian").getString("Ready_to_start..."));
        
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger(java.util.ResourceBundle.getBundle("dbmsclient/Russian").getString("StatusBar.messageTimeout"));
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox(ActionEvent e) {
         DbmsClientAboutBox dialog = new DbmsClientAboutBox(new javax.swing.JFrame());
         dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
         dialog.reloadComponents(bundle);
         dialog.setVisible(true);
     
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents

        menuBar = new javax.swing.JMenuBar();
		fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenu3 = new javax.swing.JMenu();
        jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItem2 = new javax.swing.JRadioButtonMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        mainPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        queryInputTextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        executeQueryButton = new javax.swing.JButton();
        positionLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        fileMenu.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("fileMenu.text")); // NOI18N

        bundle = java.util.ResourceBundle.getBundle("dbmsclient/Bundle"); // NOI18N
        jMenuItem1.setText(bundle.getString("help")); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        aboutMenuItem.setAction(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getActionMap(DbmsClientView.class, this).get("showAboutBox"));
        aboutMenuItem.setText(bundle.getString("DbmsClientView.aboutMenuItem.text")); // NOI18N
        fileMenu.add(aboutMenuItem);

        exitMenuItem.setAction(application.Application.getInstance(DbmsClientApp.class).getContext().getActionMap(DbmsClientView.class, this).get("quit"));
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu1.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenu1.text")); // NOI18N

        jMenuItem2.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator1);

        jMenu3.setText(bundle.getString("DbmsClientView.jMenu3.text")); // NOI18N

        jRadioButtonMenuItem1.setText(bundle.getString("DbmsClientView.jRadioButtonMenuItem1.text")); // NOI18N
        jRadioButtonMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem1ActionPerformed(evt);
            }
        });
        jMenu3.add(jRadioButtonMenuItem1);

        jRadioButtonMenuItem2.setSelected(true);
        jRadioButtonMenuItem2.setText(bundle.getString("DbmsClientView.jRadioButtonMenuItem2.text")); // NOI18N
        jRadioButtonMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jRadioButtonMenuItem2);

        jMenu1.add(jMenu3);

        menuBar.add(jMenu1);

        jMenu2.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenu2.text")); // NOI18N

        jMenuItem3.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuItem4.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem4);

        jMenuItem5.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        menuBar.add(jMenu2);

        queryInputTextArea.setColumns(20);
        queryInputTextArea.setFont(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getFont("queryInputTextArea.font")); // NOI18N
        queryInputTextArea.setLineWrap(true);
        queryInputTextArea.setRows(4);
        queryInputTextArea.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("queryInputTextArea.text")); // NOI18N
        jScrollPane1.setViewportView(queryInputTextArea);

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTable1.setFocusTraversalPolicyProvider(true);
        jTable1.setFocusable(false);
        jScrollPane2.setViewportView(jTable1);

        executeQueryButton.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getString("executeQueryButton.text")); // NOI18N
        executeQueryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                executeQueryButtonActionPerformed(evt);
            }
        });
        executeQueryButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                executeQueryButtonKeyPressed(evt);
            }
        });

        positionLabel.setText(bundle.getString("DbmsClientView.positionLabel.text")); // NOI18N

        jLabel1.setText(bundle.getString("DbmsClientView.jLabel1.text")); // NOI18N

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)))
                    .add(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel1)
                        .add(43, 43, 43)
                        .add(positionLabel))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(executeQueryButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 74, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(5, 5, 5)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(positionLabel)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(executeQueryButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 298, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        statusMessageLabel.setForeground(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientView.class).getColor("statusMessageLabel.foreground")); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
            .add(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusMessageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 376, Short.MAX_VALUE)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelLayout.createSequentialGroup()
                .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusMessageLabel)
                    .add(statusAnimationLabel)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }//GEN-END:initComponents

private void jRadioButtonMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem2ActionPerformed
   	  jRadioButtonMenuItem2.setSelected(true);
      jRadioButtonMenuItem1.setSelected(false);
	  language.setEnglish(false);
	  bundle = java.util.ResourceBundle.getBundle("dbmsclient/Russian"); 
	  reloadComponents();
   
    }//GEN-LAST:event_jRadioButtonMenuItem2ActionPerformed

private void jRadioButtonMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem1ActionPerformed
	 jRadioButtonMenuItem2.setSelected(false);
     jRadioButtonMenuItem1.setSelected(true);
	 language.setEnglish(true);
     bundle = java.util.ResourceBundle.getBundle("dbmsclient/Bundle"); 
	 reloadComponents();
    }//GEN-LAST:event_jRadioButtonMenuItem1ActionPerformed

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed

}//GEN-LAST:event_exitMenuItemActionPerformed

private void executeQueryButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_executeQueryButtonKeyPressed
    
}//GEN-LAST:event_executeQueryButtonKeyPressed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    DbmsClientHelp dialog = new DbmsClientHelp(new javax.swing.JFrame(), true);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setBundle(bundle);
    dialog.reloadComponents(bundle);
    dialog.setVisible(true);
    
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
     try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        SwingUtilities.updateComponentTreeUI(mainPanel);
        SwingUtilities.updateComponentTreeUI(statusPanel);
        SwingUtilities.updateComponentTreeUI(menuBar);
   } catch (Exception e) {
       
   }
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void reloadComponents() {
    jMenuItem1.setText(bundle.getString("help")); // NOI18N
    jMenu1.setText(bundle.getString("settings"));
    jMenu2.setText(bundle.getString("skins"));
    fileMenu.setText(bundle.getString("client"));
    aboutMenuItem.setText(bundle.getString("about"));
    exitMenuItem.setText(bundle.getString("exit"));
    jMenuItem2.setText(bundle.getString("connectSettings"));
    jMenu3.setText(bundle.getString("language"));
    jRadioButtonMenuItem1.setText(bundle.getString("english"));
    jRadioButtonMenuItem2.setText(bundle.getString("russian"));
    executeQueryButton.setText(bundle.getString("executeQuery"));
    jLabel1.setText(bundle.getString("caretPosition"));
    statusMessageLabel.setText("");
    this.getFrame().setTitle(bundle.getString("dbmsClientTitle"));
    
}

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        SwingUtilities.updateComponentTreeUI(mainPanel);
        SwingUtilities.updateComponentTreeUI(statusPanel);
        SwingUtilities.updateComponentTreeUI(menuBar);
   } catch (Exception e) {
       
   }
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
   try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(mainPanel);
    SwingUtilities.updateComponentTreeUI(statusPanel);
    SwingUtilities.updateComponentTreeUI(menuBar);
   
   } catch (Exception e) {//GEN-LAST:event_jMenuItem3ActionPerformed
       
   }
}

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
                DbmsClientSettings dialog = new DbmsClientSettings(new javax.swing.JFrame(), true);
                dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                dialog.reloadComponents(bundle);
                dialog.setVisible(true);
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void executeQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeQueryButtonActionPerformed
      
        
        try { 
            
            java.net.Socket fromserver = null;
            String toServer, fromServer;
            InetAddress hostIp  = InetAddress.getByName(dbmsclient.DbmsClientView.HOST_NAME);
            fromserver = new java.net.Socket(hostIp, dbmsclient.DbmsClientView.HOST_PORT);
            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(fromserver.getInputStream()));
            java.io.PrintWriter out = new java.io.PrintWriter(fromserver.getOutputStream(), true);
            toServer = queryInputTextArea.getText();
            out.println(toServer);
            if((fromServer = in.readLine()) == null ){
                while(fromServer != null) {
                 fromServer = in.readLine();
                }
            } 
                        
            String error = ru.dbms.client.parser.Parser.getInstance().getErrorIfExist(fromServer);
         
            if(error.length() == 0) {
                 try {
             
                    columnsHeader = ru.dbms.client.parser.Parser.getInstance().getColumnsHeader(fromServer);
                    rows = ru.dbms.client.parser.Parser.getInstance().getRows(fromServer, columnsHeader.length);
                    
                    jTable1.setModel(new javax.swing.table.DefaultTableModel(rows, columnsHeader) {
                    public boolean isCellEditable(int row, int col)
                         { return false; }    
                    });
                    Object[] obj = ru.dbms.client.parser.Parser.getInstance().getColumnsTypes(fromServer, columnsHeader.length);
                    
                    for(int i = 0; i < columnsHeader.length; i++) {
                        jTable1.getColumnModel().getColumn(i).setHeaderValue(jTable1.getColumnModel().getColumn(i).getHeaderValue() + "(" + obj[i] + ")");
                    }
                    statusMessageLabel.setText(bundle.getString("Query_done._Columns:_") + jTable1.getColumnCount() + bundle.getString("Rows") + jTable1.getRowCount());
                    
                 } catch (java.lang.Exception e) {
                    statusMessageLabel.setText(bundle.getString("error") + e.getMessage() + bundle.getString("checkQuery"));
                }
               
            } else {
                statusMessageLabel.setText(bundle.getString("error") + "\"" + error + "\"");
                JOptionPane.showMessageDialog(null, bundle.getString("error") +  "\"" + error + "\"");
                
           }
                
        } catch (UnknownHostException e) {
             statusMessageLabel.setText(bundle.getString("error") + "\"" + bundle.getString("unknowHost") + "\"");
             JOptionPane.showMessageDialog(null, bundle.getString("error") + "\"" + bundle.getString("unknowHost") + "\"");
        } catch (IOException e) {
            statusMessageLabel.setText(bundle.getString("error") + bundle.getString("cantConnect") + HOST_NAME+":"+HOST_PORT);
            JOptionPane.showMessageDialog(null, bundle.getString("error") + bundle.getString("cantConnect") + HOST_NAME+":"+HOST_PORT);
        }
   


}//GEN-LAST:event_executeQueryButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton executeQueryButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel positionLabel;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JTextArea queryInputTextArea;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
	private javax.swing.JMenuItem aboutMenuItem;
	private javax.swing.JMenuItem exitMenuItem;
	private javax.swing.JMenu fileMenu;
    // End of variables declaration//GEN-END:variables
    
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    
    private Object[][] rows;
    private Object[] columnsHeader;
    private JDialog aboutBox;
   
	public java.util.ResourceBundle bundle;
    public static String HOST_NAME = "127.0.0.1";
    public static int HOST_PORT = 65001;
 

}
